/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023.
 * Description: support rtos mem gdb debug.
 * Author: heyuqiang <heyuqiang1@huawei.com>
 * Create: 2023-09-05
 * Note: this file isn't compiled independently, it is includded
 * in memory.c
 */

#include <asm/io.h>
#include <asm/pgalloc.h>
#include "rtos_gdb_debug.h"

void __iomem *ioremap_gdb(phys_addr_t phys_addr, unsigned long prot)
{
	void __iomem *maddr = NULL;

#ifdef CONFIG_ARM64
	prot = (prot & PMD_ATTRINDX_MASK)
		| (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE);
	maddr = __ioremap(phys_addr, PAGE_SIZE, __pgprot(prot));
#endif
#ifdef CONFIG_ARM
	if ((prot & PMD_SECT_WB) == PMD_SECT_WB)
		maddr = ioremap_cache(phys_addr, PAGE_SIZE);
	else if ((prot & PMD_SECT_WB) == PMD_SECT_BUFFERED)
		maddr = ioremap_wc(phys_addr, PAGE_SIZE);
	else if ((prot & PMD_SECT_WB) == PMD_SECT_UNCACHED)
		maddr = ioremap(phys_addr, PAGE_SIZE);
	else
		return ERR_PTR(-EINVAL);
#endif
	return maddr;
}
